<!DOCTYPE html>
<!--suppress ALL-->
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户消息管理</title>
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.7.0/themes/metro-blue/easyui.css">
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.7.0/themes/icon.css">
    <script type="text/javascript" src="/static/jquery-easyui-1.7.0/jquery.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.7.0/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.7.0/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        var url;

        function searchInformation() {
            $("#dg").datagrid('load', {
                "userId": $("#s_userId").combogrid("getValue")
            });
        }

        function resetValue() {
            $("#add_userId").combobox("setValue", "");
            $("#add_content").val("");
            $("#s_userId").combogrid("setValue", "");
        }

        function openInformationAddDialog() {
            $("#dlg").dialog("open").dialog("setTitle", "发送信息");
            url = "/admin/information/add";
        }

        function closeInformationDialog() {
            $("#dlg").dialog("close");
            resetValue();
        }

        function saveInformation() {
            var content = $("#add_content").val();
            if (content == null || content == "") {
                alert("内容不能为空!");
                return false;
            }
            $("#fm").form("submit", {
                url: url,
                onSubmit: function () {
                    return $(this).form("validate");
                },
                success: function (result) {
                    var result = eval('(' + result + ')');
                    if (result.success) {
                        $.messager.alert("系统提示", "保存成功！");
                        resetValue();
                        $("#dlg").dialog("close");
                        $("#dg").datagrid("reload");
                    } else {
                        $.messager.alert("系统提示", "保存失败!");
                    }
                }
            });
        }

        function deleteInformation() {
            var selectedRows = $("#dg").datagrid("getSelections");
            if (selectedRows.length == 0) {
                $.messager.alert("系统提示", "请选择要删除的数据！");
                return;
            }
            var strIds = [];
            for (var i = 0; i < selectedRows.length; i++) {
                strIds.push(selectedRows[i].id);
            }
            var ids = strIds.join(",");
            $.messager.confirm("系统提示", "您确定要删除这<span style='color: red'>" + selectedRows.length + "</span>条数据吗?", function (r) {
                if (r) {
                    $.post("/admin/information/delete", {ids: ids}, function (result) {
                        if (result.success) {
                            $.messager.alert("系统提示", "数据已成功删除！");
                            $("#dg").datagrid("reload");
                        } else {
                            $.messager.alert("系统提示", result.errorInfo);
                        }
                    }, "json");
                }
            });
        }

        function formatContent(val, row) {
            if (val.length > 30) {
                return "<span title='" + val + "'>" + val.substring(0, 30) + "...</span>";
            } else {
                return "<span title='" + val + "'>" + val + "</span>";
            }
        }

        function formatUser(val, row) {
            return val.userName;
        }
    </script>
</head>
<body style="margin: 1px">
<table id="dg" title="用户消息管理" class="easyui-datagrid" striped="true"
       fitColumns="true" pagination="true" rownumbers="true"
       url="/admin/information/list" fit="true" toolbar="#tb">
    <thead>
    <th field="cb" checkbox="true" align="center"></th>
    <th field="id" width="20" align="center" hidden="hidden">编号</th>
    <th field="user" width="10" align="center" formatter="formatUser">用户名</th>
    <th field="date" width="10" align="center">时间</th>
    <th field="content" width="50" align="center" formatter="formatContent">内容</th>
    </thead>
</table>

<div id="tb">
    <div>
        <a href="javascript:openInformationAddDialog()" class="easyui-linkbutton" iconCls="icon-sendMessage"
           plain="true">发消息</a>
        <a href="javascript:deleteInformation()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
        <span style="color: red">(鼠标停在内容上可以看到详细信息,下拉框可键盘输入:在下拉框中输入内容时请选择提示中的内容,不然输入的用户名有可能不存在,搜索不到相关数据)</span>
    </div>
    <div>
        &nbsp;用户名：&nbsp;
        <select id="s_userId" name="userId" class="easyui-combogrid" style="width:140px" data-options="
			panelWidth: 800,
			idField: 'id',
			textField: 'userName',
			url: '/admin/user/comboList',
			method: 'get',
			columns: [[
				{field:'id',title:'编号',width:40},
				{field:'userName',title:'用户名',width:60},
				{field:'nickName',title:'昵称',width:60,align:'right'},
				{field:'roleName',title:'身份',width:60,align:'right'},
				{field:'email',title:'邮箱',width:100},
			]],
			fitColumns: true
		">
        </select>
        <a href="javascript:searchInformation()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
        <a href="javascript:resetValue()" class="easyui-linkbutton" iconCls="icon-reset" plain="true">重置</a>
    </div>
</div>


<div id="dlg" class="easyui-dialog" style="width: 422px;height: 244px;padding: 10px 20px"
     closed="true" buttons="#dlg-buttons" data-options="onClose:function(){resetValue()}">
    <form id="fm" method="post">
        <table cellspacing="8px">
            <tr>
                <td valign="top">用户名:</td>
                <td>
                    <input class="easyui-combobox" id="add_userId" name="userId" required="true" style="width: 140px"
                           editable="true" onkeydown="if(event.keyCode==13) searchInformation()"
                           data-options="panelHeight:'auto',valueField:'id',textField:'userName',url:'/admin/user/comboList'"/>
                </td>
            </tr>
            <tr>
                <td valign="top">内容:</td>
                <td>
                    <textarea id="add_content" name="content" required="true" rows="5" cols="40"></textarea>
                </td>
            </tr>
        </table>
    </form>
</div>

<div id="dlg-buttons">
    <a href="javascript:saveInformation()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
    <a href="javascript:closeInformationDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>
</body>
</html>